<?php
namespace App\Http\Controllers\Admin;
use App\Handlers\ImageUploadHandler;
use App\Http\Requests\BannerRequest;
use App\Models\distribution;
use App\Models\Order;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\User;
class UserController extends Controller
{
    public function index(Request $request)
    {
        $serach = [];
        $key    = '';
        $val    = '';
        $input= $request->all();
        if (!empty($input)){
            $key  = key($input);
            $val  = current($input);
            $serach['key'] = $key;
            $serach['val'] = $val;
        }
        $data = User::getUserList($key,$val);
        return view('admin.user.index',['lists'=>$data,'search'=>$serach]);
    }

    public function destroy(int $id){
        if ($id<=0){#id错误 提早退出 代码不必执行
            return;
        }
        $flag = User::destroy($id);
        if($flag){
            return redirect()->back()->with('success','删除成功');
        }else{
            return redirect()->back()->with('danger','删除失败');
        }
    }


    /**禁用用户
     * @param int $id
     * @return \Illuminate\Http\RedirectResponse|void
     */
    public function disabled(int $id)
    {
        if ($id<=0){
            return;
        }
        $flag = User:: where('id', $id)->update(['is_disabled' => 1]);
        if($flag){
            return redirect()->back()->with('success','删除成功');
        }else{
            return redirect()->back()->with('danger','删除失败');
        }
    }


    public function rebateBenefit(int $id)
    {
        if ($id<=0){
            return;
        }
        $data = distribution::getMyBenefitList($id);
        return view('admin.user.rebateBenefit',['lists'=>$data['data'],'id'=>$id]);
    }


    public function rebateDevote(int $id)
    {
        if ($id<=0){
            return;
        }
        $data = distribution::getMyDevoteList($id);
        return view('admin.user.rebateDevote',['lists'=>$data['data']]);
    }


    public function getUserList()
    {

    }






}
